/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//TODO Add description

$(document).ready(function(){
    $('#login').on('click', loginController.buttonListener);
    $('#register').on('click', loginController.buttonListener);
    $('#logout').on('click', loginController.buttonListener);
})

var loginController = (function () {
    return {
        buttonListener: function() {
            if (this.id === "register") {
                var regDialog = new Dialog();
                regDialog.addHandler(loginController.regDialogListener);
                regDialog.setParent("#dialog");
                regDialog.render();
            } else if (this.id === "login") {
                var loginDialog = new Dialog();
                loginDialog.addHandler(loginController.loginDialogListener);
                loginDialog.setParent("#dialog");
                loginDialog.render();
            } else if (this.id === "logout") {
                window.location = "http://localhost:8080/weba_novare/index.xhtml";
            }
        },
        
        loginDialogListener: function(user) {
            alert("Vill logga in som: " + user.name);
            //Check if user is registered, wrote a correct username and password
            window.location = "http://localhost:8080/weba_novare/welcome.xhtml";
        }
    }
}());
